/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.gu.derp.model;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author c
 */
public class Mail {

    private static final String HOST = "smtp.gmail.com";
    private static final int PORT = 465;
    private static final String USER = "test@hawk-an.com";
    private static final String PASSWORD = "testtest";

    public static void sendWelcomeMail(Account account) throws MessagingException {
        String subject = "Registration";
        String text = "Welcome!\n\nYour username is: " + account.getUsername() + "\nYour password is: " + account.getPassword()
                + "\nherping le derp";
        sendMail(account, subject, text);

    }

    public static void sendUnregMail(Account account) throws MessagingException {
        String subject = "Unregistration";
        String text = "Y U DONT DO LE DERP!!!!11one1on ";
        sendMail(account, subject, text);
    }

    private static void sendMail(Account account, String subject, String text) throws MessagingException {
        String recipient = account.getEmail();
        Properties props = new Properties();

        props.put("mail.transport.protocol", "smtps");
        props.put("mail.smtps.host", HOST);
        props.put("mail.smtps.auth", "true");
        // props.put("mail.smtps.quitwait", "false");

        Session mailSession = Session.getDefaultInstance(props);
        mailSession.setDebug(true);
        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject(subject);
        message.setContent(text, "text/plain");

        message.addRecipient(Message.RecipientType.TO,
                new InternetAddress(recipient));

        transport.connect(HOST, PORT, USER, PASSWORD);

        transport.sendMessage(message,
                message.getRecipients(Message.RecipientType.TO));

        transport.close();
    }
}
